package util.src.com;

import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

/**
 * @Author: Gosin
 * @Date: 2020/11/3 17:11
 */
public class getFfmpegFile extends WriteText {
    public String m3u8Path = "D:\\乱七八糟\\Downloads\\3\\";
    public String tsPath = m3u8Path + "1\\";
    public String allFileTextPath;
    public String allFileTextName;
    public String errorFileTextPath;
    public String errorFileTextName;
    public String ffmpegTextPath;
    public String ffmpegTextName;


    List<String> fileNames;
    Collection errorFileNames = new ArrayList();


    public getFfmpegFile(String allFileTextPath, String allFileTextName, String ffmpegTextPath, String ffmpegTextName, String errorFileTextPath, String errorFileTextName) throws IOException {
        super(allFileTextPath, allFileTextName, ffmpegTextPath, ffmpegTextName);
        this.allFileTextPath = allFileTextPath;
        this.allFileTextName = allFileTextName;
        this.ffmpegTextPath = ffmpegTextPath;
        this.ffmpegTextName = ffmpegTextName;
        this.errorFileTextPath = errorFileTextPath;
        this.errorFileTextName = errorFileTextName;

        BufferedReader errorFileTextReader = new BufferedReader(new InputStreamReader(new FileInputStream(errorFileTextPath + errorFileTextName)));
        String line;
        String msg;
        while ((line = errorFileTextReader.readLine()) != null) {
            msg = line.split("/")[line.split("/").length - 1];
            if (msg != null) {
                errorFileNames.add(msg);
            }
        }
        errorFileTextReader.close();
    }

    public static void main(String[] args) throws IOException {
        String allFileTextPath = "D:\\乱七八糟\\Downloads\\4\\";
        String allFileTextName = "a.txt";
        String errorFileTextPath = allFileTextPath;
        String errorFileTextName = "e.txt";
        String ffmpegTextPath = allFileTextPath;
        String ffmpegTextName = "f.txt";

        getFfmpegFile a = new getFfmpegFile(allFileTextPath, allFileTextName, ffmpegTextPath, ffmpegTextName, errorFileTextPath, errorFileTextName);
        a.getTsUrlText();
    }

    @Override
    protected String selectUrl(String line) {
        //挑选时还要保证顺序不能错
        if (line != null) {
            //使用readLine方法，一次读一行
            if (!errorFileNames.isEmpty()) {
                if (errorFileNames.contains(line.split("/")[line.split("/").length - 1])) {
                    return null;
                }
            }
            return "file " + line.split("/")[line.split("/").length - 1];
        }
        //添加元素
        return null;
    }
}

